<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jq-1.12.4.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            font-family: '微软雅黑';
        }

        .contain {
            width: 320px;
            margin: 5px auto;
            border: 1px solid #2a65ba;
            position: absolute;
            top: 100px;
            left: 100px;
        }

        .gameList {
            list-style: none;
        }

        .gameList li {
            padding-left: 15px;
            line-height: 40px;
            height: 40px;
            font-size: 12px;
            color: #000;
            border-bottom: 1px #aaaaaa dashed;
        }

        h2 {
            font-size: 16px;
            padding-left: 20px;
            line-height: 40px;
        }
    </style>

</head>

<body style="height: 2000px;width: 1500px;">
    <div class="contain">
        <div>
            <img src="../img/winter.jpg" alt="奥运五环标志" width="320" height="198">
        </div>
        <h2>祝福冬奥</h2>
        <ul class="gameList">
            <li> 1贝克汉姆：衷心希望北京能够申办成功！</li>
            <li> 2姚明：北京申冬奥是个非常棒的机会！加油！</li>
            <li> 3张虹：北京办冬奥，大家的热情定超乎想象！ </li>
            <li> 4肖恩怀特：我爱北京，支持北京申办冬奥会！</li>
        </ul>
    </div>
</body>
<script>
    //end()用法
    $(function () {
        $(".gameList>li").first().css("background-color", "#b8e7f9").end().last().css("background-color", "#f8e7f9").end().eq(1).css("background-color", "yellow")
    })

    //2.获得contain的top和left值
    $(function () {
        //找到到元素
        let obj = $(".contain").offset()
        console.log(obj.top, obj.left);
        //设置
        $(".contain").offset({
            "top": "obj.top",
            "left": "obj.left+200"
        })
        console.log($(".contain").css("right"))
        console.log($(".contain").css("bottom"))

        //相对于第一个定位元素而言的
        console.log($(".contain").position())
    })

    $(function () {
        let obj = $(".contain").offset()
        //监听文档的滚动距离
        $(document).scroll(function () {
            let top = $(this).scrollTop()
            let left = $(this).scrollLeft()
            $(".contain").css({
                "top": obj.top + top + "px",
                "left": obj.left + left + "px"
            })
        })
    })

</script>

</html>